﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace fingerWinForm.GUI
{
    public partial class SVMResultsWindow_ThreeClasses : Form
    {
        private double[,] allCombinationsConfusionMatrix;
        private double[,] cAndGammaConfusionMatrix;
        private double[] sumGradesInPredictFileForAllCombinations;
        private double[] sumGradesInPredictFileForCAndGamma;
        public SVMResultsWindow_ThreeClasses()
        {
            allCombinationsConfusionMatrix = new double[5, 5];
            cAndGammaConfusionMatrix = new double[5,5];
            sumGradesInPredictFileForAllCombinations = new double[5];
            sumGradesInPredictFileForCAndGamma = new double[5];
            InitializeComponent();
        }

        private void comboBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

        private void comboBox_TextChanged(object sender, EventArgs e)
        {
            if (comboBox.Text == "All C and Gamma combinations")
            {
                copyDataToSvmResultsWindowForAllCombinations();
            }
            else
            {
                copyDataToSvmResultsWindowForCAndGamma();
            }
        }

        public void setAllCombinationsConfusionMatrix(double[,] matrix, double[] sumMatrix)
        {
            allCombinationsConfusionMatrix = matrix;
            sumGradesInPredictFileForAllCombinations = sumMatrix;
            copyDataToSvmResultsWindowForAllCombinations();
        }

        public void setCAndGammaConfusionMatrix(double[,] matrix, double[] sumMatrix)
        {
            cAndGammaConfusionMatrix = matrix;
            sumGradesInPredictFileForCAndGamma = sumMatrix;
        }

        public void setComboBoxLabel()
        {
            comboBox.Text = "All C and Gamma combinations";
        }

        public void copyDataToSvmResultsWindowForAllCombinations()
        {
            if (sumGradesInPredictFileForAllCombinations[0] != 0)
            {
                label11.Text = (allCombinationsConfusionMatrix[0, 0] / sumGradesInPredictFileForAllCombinations[0]).ToString("f4");
                label21.Text = (allCombinationsConfusionMatrix[1, 0] / sumGradesInPredictFileForAllCombinations[0]).ToString("f4");
                label31.Text = (allCombinationsConfusionMatrix[2, 0] / sumGradesInPredictFileForAllCombinations[0]).ToString("f4");
            }
            else
            {
                label11.Text = "0.0000";
                label21.Text = "0.0000";
                label31.Text = "0.0000";
            }

            if (sumGradesInPredictFileForAllCombinations[1] != 0)
            {
                label12.Text = (allCombinationsConfusionMatrix[0, 1] / sumGradesInPredictFileForAllCombinations[1]).ToString("f4");
                label22.Text = (allCombinationsConfusionMatrix[1, 1] / sumGradesInPredictFileForAllCombinations[1]).ToString("f4");
                label32.Text = (allCombinationsConfusionMatrix[2, 1] / sumGradesInPredictFileForAllCombinations[1]).ToString("f4");
            }
            else
            {
                label12.Text = "0.0000";
                label22.Text = "0.0000";
                label32.Text = "0.0000";
            }

            if (sumGradesInPredictFileForAllCombinations[2] != 0)
            {
                label13.Text = (allCombinationsConfusionMatrix[0, 2] / sumGradesInPredictFileForAllCombinations[2]).ToString("f4");
                label23.Text = (allCombinationsConfusionMatrix[1, 2] / sumGradesInPredictFileForAllCombinations[2]).ToString("f4");
                label33.Text = (allCombinationsConfusionMatrix[2, 2] / sumGradesInPredictFileForAllCombinations[2]).ToString("f4");
            }
            else
            {
                label13.Text = "0.0000";
                label23.Text = "0.0000";
                label33.Text = "0.0000";
            }
        }

        public void copyDataToSvmResultsWindowForCAndGamma()
        {
            if (sumGradesInPredictFileForCAndGamma[0] != 0)
            {
                label11.Text = (cAndGammaConfusionMatrix[0, 0] / sumGradesInPredictFileForCAndGamma[0]).ToString("f4");
                label21.Text = (cAndGammaConfusionMatrix[1, 0] / sumGradesInPredictFileForCAndGamma[0]).ToString("f4");
                label31.Text = (cAndGammaConfusionMatrix[2, 0] / sumGradesInPredictFileForCAndGamma[0]).ToString("f4");
            }
            else
            {
                label11.Text = "0.0000";
                label21.Text = "0.0000";
                label31.Text = "0.0000";
            }

            if (sumGradesInPredictFileForCAndGamma[1] != 0)
            {
                label12.Text = (cAndGammaConfusionMatrix[0, 1] / sumGradesInPredictFileForCAndGamma[1]).ToString("f4");
                label22.Text = (cAndGammaConfusionMatrix[1, 1] / sumGradesInPredictFileForCAndGamma[1]).ToString("f4");
                label32.Text = (cAndGammaConfusionMatrix[2, 1] / sumGradesInPredictFileForCAndGamma[1]).ToString("f4");
            }
            else
            {
                label12.Text = "0.0000";
                label22.Text = "0.0000";
                label32.Text = "0.0000";
            }

            if (sumGradesInPredictFileForCAndGamma[2] != 0)
            {
                label13.Text = (cAndGammaConfusionMatrix[0, 2] / sumGradesInPredictFileForCAndGamma[2]).ToString("f4");
                label23.Text = (cAndGammaConfusionMatrix[1, 2] / sumGradesInPredictFileForCAndGamma[2]).ToString("f4");
                label33.Text = (cAndGammaConfusionMatrix[2, 2] / sumGradesInPredictFileForCAndGamma[2]).ToString("f4");
            }
            else
            {
                label13.Text = "0.0000";
                label23.Text = "0.0000";
                label33.Text = "0.0000";
            }
        }
           
    }
}
